<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <style>
        *{
            margin: 0;
            padding: 0;
        }
        .box{
            width: 200px;
            height: 200px;
            margin: 100px auto;
            background-color: rgb(241, 62, 18);
        }
        p{
            font-size: 18px;
            transition: 0.5s linear;
        }
    </style>
</head>
<body>
    <div class="box">
        <p>你好</p>
    </div>
    <script>
        var EventHand={
            addEvent:function(ele,type,fu,boolean){
                if (ele.addEventListener) {
                    ele.addEventListener(type,fn,boolean);
                }else if(ele.attachEvent){
                    ele.attachEvent(type,fn,boolean);
                }else{
                    ele["on"+type]=fu;
                }
            },
            removeEvent:function(ele,type,fu){
                if (ele.addEventListener) {
                    ele.removeEventListener(type,fn);
                }else if(ele.attachEvent){
                    ele.deleteEvent(type,fn);
                }else{
                    ele["on"+type]=null;
                }
            }


        }
        function fn (event){
            count++;
            alert("你点击"+count+"次,还剩下"+(maxCount-count)+"次数,请注意!")
            if (count==maxCount) {
                alert("次数用完 结束了!")
                box.removeEventListener(event.type,arguments.callee,false);
            }
        }
        var box=document.querySelector(".box");
        var count=0;
        const maxCount=5;
        EventHand.addEvent(box,"click",fn,false);





       
        // var p=document.querySelector("p");
        // var count=0;
        // const maxCount=5;
        // box.addEventListener("click",function(event){
        //     count++;
        //     alert("你点击"+count+"次,还剩下"+(maxCount-count)+"次数,请注意!")
        //     if (count==maxCount) {
        //         alert("次数用完 结束了!")
        //         box.removeEventListener(event.type,arguments.callee,false);
        //     }
        // },false);


        

        
    </script>
</body>
</html>